package main.bufferIO;

import java.io.*;

public class BufferStream {
    public static void main(String[] args) {
        try {
            //inputS("data//rr.txt");
            outputS("data//rrOut.txt");
            //copyFile("data//rr.txt","data//rrOut.txt");

        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public static void inputS(String filePath) throws IOException {
        File file = new File(filePath);
        //文件字节输入流
        FileInputStream in = new FileInputStream(file);
        //文件字节输入流放到缓冲字节输入流对象
        BufferedInputStream bIn = new BufferedInputStream(in);

        byte[] b = new byte[10];
        int len = 0;
        while((len = bIn.read(b))!=-1){
            System.out.println(new String(b,0,len));
        }
        bIn.close();
        in.close();
    }
    public static void outputS(String filePath) throws IOException {
        FileOutputStream out = new FileOutputStream(filePath,false);
        BufferedOutputStream bOut = new BufferedOutputStream(out);
        String str = "who is you?";
        bOut.write(str.getBytes());
        bOut.flush();
        bOut.write(str.getBytes());
        bOut.flush();
        bOut.close();
        out.close();
    }
    public  static void copyFile(String inputFilePath , String outputFilePath) throws IOException{
        BufferedInputStream bIn = new BufferedInputStream(new FileInputStream(inputFilePath));
        BufferedOutputStream bOut = new BufferedOutputStream(new FileOutputStream(outputFilePath));

        byte[] b = new byte[4];
        int len = 0;
        while((len = bIn.read(b))!=-1){
            bOut.write(b,0,len);
            bOut.flush();
        }
        //bOut.flush();
        bOut.close();
        bIn.close();
    }
}
